﻿namespace = bride_show

scripted_trigger agrees_with_bride_show = {
	OR = {
		culture = { has_cultural_tradition = tradition_ep3_palace_politics }
		culture = { has_cultural_tradition = tradition_legalistic }
		hp_accepts_concubinage = yes
		hp_accepts_polygamy = yes
	}
}

scripted_trigger can_have_four_candidates_trigger = {
	OR = {
		highest_held_title_tier >= tier_empire
		any_vassal = {
			count >= 9
		}
	}
}

scripted_effect bride_show_add_to_candidate_list_effect = {
	if = {
		limit = { 
			bride_show_viable_candidate_trigger = {
				OVERLORD = scope:liege
			} 
		}
		add_to_list = elegible_candidates_list
	}
}

scripted_effect bride_show_next_candidate_effect = {
	if = {
		limit = { #I can still pick candidates
			OR = {
				NOT = {		
					exists = scope:candidate_3
				}
				AND = {	
					NOT = {		
						exists = scope:candidate_4
					}
					can_have_four_candidates_trigger = yes
				}
			}
		}
		#Characters will be created only if not at least 4 candidates
		if = {
			limit = { 
				OR = { 
					any_in_list = {
						list = elegible_candidates_list
						count = 0
					}
					any_in_list = { #Or in case all of them are teens
						list = elegible_candidates_list
						is_adult = no
						count = all
					}
					AND = { #Or if there aren't any candidates with good congenital traits
						NOT = { exists = scope:candidate_1 }
						scope:liege = { has_variable = beauty_important }
						any_in_list = {
							list = elegible_candidates_list
							OR = {	
								has_trait = beauty_good
								has_trait = physique_good
							}
							count = 0
						}
					}
				}
			}
			calyver_create_candidate_effect = yes
			scope:bride = {
				add_to_list = elegible_candidates_list
				add_to_list = created_candidates_list
				add_character_flag = created_bride_flag
			}
			clear_saved_scope = bride
		}
		if = {
			limit = {
				any_in_list = {
					list = elegible_candidates_list
					count = 1
				}
			}
			random_in_list = {
				list = elegible_candidates_list
				save_scope_as = potential_candidate
			}
		}
		else = {
			random_in_list = {
				list = elegible_candidates_list
				weight = {
					base = 10
					modifier = { #Non-rejected consorts are preferred
						is_demoted_consort_trigger = no
						add = 10
					}
					modifier = { #Ready to be consorts are preferred
						is_adult = yes
						add = 25
					}
					modifier = { #Powerful candidates are preferred
						is_lowborn = no
						add = 10
					}
					modifier = { #More if it was set
						scope:liege = { has_variable = family_background_important }
						is_lowborn = no
						add = 20
					}
					modifier = { #Children of vassals are preferred
						any_close_or_extended_family_member = {
							OR = {	
								is_vassal_of = root
								is_tributary_of = root
							}
						}
						add = 5
					}
					modifier = { #More if it was set
						any_close_or_extended_family_member = {
							OR = {	
								is_vassal_of = root
								is_tributary_of = root
							}
						}
						scope:liege = { has_variable = family_background_important }
						add = 25
					}
					modifier = { #Child of powerful vassals are preferred
						any_close_family_member = {
							OR = {
								is_powerful_vassal_of = root
								is_councillor_of = root
								is_parent_of = root
							}
						}
						add = 10
					}
					modifier = { #Child of tributaries are preferred
						any_close_family_member = {
							is_tributary_of = scope:liege
							tier_difference = {
								target = scope:liege
								value >= -1
							}
						}
						add = 15
					}
					modifier = { #More if it was set
						any_close_family_member = {
							OR = {
								is_powerful_vassal_of = root
								is_councillor_of = root
								is_parent_of = root
								AND = {
									is_tributary_of = root
									is_lowborn = no
								}
							}
						}
						scope:liege = { has_variable = family_background_important }
						add = 50
					}
					modifier = { #More if it was set
						any_close_family_member = {
							government_has_flag = government_is_administrative
							top_liege ?= scope:liege
							house ?= {
								is_dominant_family = yes
							}
						}
						scope:liege = { 
							has_variable = family_background_important 
							government_has_flag = government_is_administrative
						}
						add = 75
					}
					modifier = { #Noble rank
						any_close_family_member = {
							highest_held_title_tier >= tier_county
						}
						add = 5
					}
					modifier = { #Noble rank - preference for powerful background
						any_close_family_member = {
							highest_held_title_tier >= tier_county
						}
						scope:liege = { has_variable = family_background_important }
						add = 5
					}
					modifier = { #Ducal rank - preference for powerful background
						any_close_family_member = {
							highest_held_title_tier >= tier_duchy
						}
						scope:liege = { has_variable = family_background_important }
						add = 5
					}
					modifier = { #Royal rank - preference for powerful background
						any_close_family_member = {
							highest_held_title_tier >= tier_kingdom
						}
						scope:liege = { has_variable = family_background_important }
						add = 10
					}
					modifier = { #Imperial rank - preference for powerful background
						any_close_family_member = {
							highest_held_title_tier >= tier_empire
						}
						scope:liege = { has_variable = family_background_important }
						add = 5
					}
					modifier = { #Nepotism wins if family background is important
						any_close_or_extended_family_member = {
							is_close_or_extended_family_of = root
						}
						scope:liege = { has_variable = family_background_important }
						add = 15
					}
					modifier = { #Trait considerations
						num_of_good_genetic_traits >= 1
						add = 5
					}
					modifier = { #Trait considerations - beauty is important
						has_trait = strong
						scope:liege = { has_variable = beauty_important }
						add = 10
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_1
							has_trait = physique_good_1
						}
						scope:liege = { has_variable = beauty_important }
						add = 40
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_1
							has_trait = physique_good_1
						}
						scope:liege = { 
							has_variable = beauty_important 
							NOT = {
								any_consort = {
									OR = {
										has_trait = beauty_good_1
										has_trait = physique_good_1
									}
								}
							}
						}
						add = 40
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_2
							has_trait = physique_good_2
						}
						scope:liege = { has_variable = beauty_important }
						add = 50
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_2
							has_trait = physique_good_2
						}
						scope:liege = { 
							has_variable = beauty_important 
							NOT = {
								any_consort = {
									OR = {
										has_trait = beauty_good_2
										has_trait = physique_good_2
									}
								}
							}
						}
						add = 50
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_3
							has_trait = physique_good_3
						}
						scope:liege = { has_variable = beauty_important }
						add = 60
					}
					modifier = { #Trait considerations - beauty is important
						OR = {
							has_trait = beauty_good_3
							has_trait = physique_good_3
						}
						scope:liege = { 
							has_variable = beauty_important 
							NOT = {
								any_consort = {
									OR = {
										has_trait = beauty_good_3
										has_trait = physique_good_3
									}
								}
							}
						}
						add = 60
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_sinful_traits > 0
						scope:liege = { has_variable = personality_skills_important }
						add = -10
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_sinful_traits >= 2
						scope:liege = { has_variable = personality_skills_important }
						add = -10
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_sinful_traits >= 3
						scope:liege = { has_variable = personality_skills_important }
						add = -10
					}
					modifier = { #Bonus for virtuous candidates - if virtuous traits matter
						AND = {
							num_sinful_traits = 0
							num_virtuous_traits >= 1
						}
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_virtuous_traits >= 1
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_virtuous_traits >= 2
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Virtuous traits are encouraged - if they were chosen
						num_virtuous_traits >= 3
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Skill considerations - if they were chosen
						OR = {
							stewardship >= 9
							diplomacy >= 9
							learning >= 9
						}
						scope:liege = { has_variable = personality_skills_important }
						add = 5
					}
					modifier = { #Skill considerations - if they were chosen
						OR = {
							stewardship >= 13
							diplomacy >= 13
							learning >= 13
						}
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Skill considerations - if they were chosen
						OR = {
							stewardship >= 17
							diplomacy >= 17
							learning >= 17
						}
						scope:liege = { has_variable = personality_skills_important }
						add = 15
					}
					modifier = { #Bonus - skill considerations - if they were chosen
						AND = {
							stewardship >= 13
							diplomacy >= 13
							learning >= 13
						}
						scope:liege = { has_variable = personality_skills_important }
						add = 20
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = content
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = calm
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = gregarious
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = compassionate
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = forgiving
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = honest
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen - bonus for non-scheming consorts
						harem_politics_evil_consort_trigger = no
						scope:liege = { has_variable = personality_skills_important }
						add = 10
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_1
						scope:liege = { has_variable = personality_skills_important }
						add = 15
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_1
						scope:liege = { 
							has_variable = personality_skills_important 
							NOT = {
								any_consort = {
									has_trait = intellect_good_1
								}
							}
						}
						add = 15
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_2
						scope:liege = { has_variable = personality_skills_important }
						add = 25
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_2
						scope:liege = { 
							has_variable = personality_skills_important 
							NOT = {
								any_consort = {
									has_trait = intellect_good_2
								}
							}
						}
						add = 25
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_3
						scope:liege = { has_variable = personality_skills_important }
						add = 35
					}
					modifier = { #Trait considerations - if they were chosen
						has_trait = intellect_good_3
						scope:liege = { 
							has_variable = personality_skills_important 
							NOT = {
								any_consort = {
									has_trait = intellect_good_3
								}
							}
						}
						add = 35
					}
					# Poets
					modifier = {
						has_trait = poet
						scope:liege = { has_variable = personality_skills_important }
						add = 15
					}
					# Skills
					modifier = { #Diplomacy
						add = {
							value = diplomacy
							divide = 2
						}
					}
					modifier = { #Learning
						add = {
							value = learning
							divide = 2
						}
					}
					modifier = { #Intrigue
						add = {
							value = intrigue
							divide = 2
						}
					}
					modifier = { #Scheming consorts will try their best to be chosen... and they make the harem interesting
						harem_politics_evil_consort_trigger = yes
						NOT = { scope:liege = { has_variable = personality_skills_important } }
						add = 15
					}
					modifier = { #Parents would not leave their children
						any_child = {
							even_if_dead = yes
							count = 0
						}
						add = 40
					}
					modifier = { #Virginity is valuable
						is_virgin_trigger = yes
						add = 40
					}
					modifier = { #Characters that believe in concubinage are more elegible
						hp_accepts_harems = yes
						add = 10
					}
				}
				save_scope_as = potential_candidate
			}
		}
	}

	#Are we done? Yes
	if = {
		limit = {
			OR = {
				AND = {	
					exists = scope:candidate_3
					can_have_four_candidates_trigger = no
				}
				exists = scope:candidate_4
			}
		}
		trigger_event = bride_show.0006
	}
	#No
	else = {
		trigger_event = bride_show.0005
	}
}

#######################
##Choosing parameters##
#######################

##Family background##
bride_show.0001 = { 
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_m_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_m_tribal.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
				}
				desc = bride_show.0001_m.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_f_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_f_tribal.t
			}
			desc = bride_show.0001_f.t
		}
		desc = bride_show.0001.t
	}
	desc = bride_show.0001.desc
	theme = realm
	
	left_portrait = { 	
		character = root
		animation = personality_honorable
	}
	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:liege }
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
	}
	# Family background is important
	option = {
		name = bride_show.0001.a
		trigger = {
			gold >= tiny_gold_value
		}
		show_as_unavailable = {
			gold < tiny_gold_value
		}

		remove_short_term_gold = tiny_gold_value
		
		set_variable = {
			name = family_background_important
			value = yes
			days = 30
		}
		ai_chance = { #The AI will always choose this
			base = 20
			modifier = {
				gold < minor_gold_value
				factor = 0
			}
		}
	}

	#It's irrelevant
	option = {
		name = bride_show.0001.b
		ai_chance = {
			base = 5
		}
	}
	after = {
		trigger_event = {
			id = bride_show.0002
			days = { 5 10 }
		}
	}
}

##Beauty##
bride_show.0002 = { 
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_m_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_m_tribal.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
				}
				desc = bride_show.0001_m.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_f_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_f_tribal.t
			}
			desc = bride_show.0001_f.t
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = yes
				}
				desc = bride_show.0002.t.f
			}
			desc = bride_show.0002.t.m
		}
	}
	desc = bride_show.0002.desc
	theme = realm
	
	right_portrait = { 	
		character = root
		animation = personality_rational
	}
	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:liege }
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
	}
	# Beauty is important
	option = {
		name = bride_show.0002.a
		trigger = {
			gold >= tiny_gold_value
		}
		show_as_unavailable = { NOT = { gold >= tiny_gold_value } }
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= tiny_gold_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}
		remove_short_term_gold = tiny_gold_value
		set_variable = {
			name = beauty_important
			value = yes
			days = 30
		}
		ai_chance = { #The AI will always choose this
			base = 20
			modifier = {
				gold < minor_gold_value
				factor = 0
			}
		}
	}

	#It's irrelevant
	option = {
		name = bride_show.0001.b
		ai_chance = {
			base = 1
		}
	}
	after = {
		trigger_event = {
			id = bride_show.0003
			days = { 5 10 }
		}
	}
}

##Personality and skills##
bride_show.0003 = { 
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_m_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_m_tribal.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
				}
				desc = bride_show.0001_m.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0001_f_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0001_f_tribal.t
			}
			desc = bride_show.0001_f.t
		}
		desc = bride_show.0003.t
	}
	desc = bride_show.0003.desc
	theme = realm
	
	left_portrait = { 	
		character = root
		animation = personality_compassionate
	}
	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:liege }
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
	}
	# Personality and skills are important
	option = {
		name = bride_show.0003.a
		trigger = {
			gold >= tiny_gold_value
		}
		show_as_unavailable = { NOT = { gold >= tiny_gold_value } }
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= tiny_gold_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}
		remove_short_term_gold = tiny_gold_value
		set_variable = {
			name = personality_skills_important
			value = yes
			days = 30
		}
		ai_chance = {
			base = 1
		}
	}

	#It's irrelevant
	option = {
		name = bride_show.0001.b
		ai_chance = { #The AI will always choose this
			base = 15
		}
	}
	after = {
		trigger_event = {
			id = bride_show.1001
			days = { 10 15 }
		}
	}
}

##The show starts##
bride_show.0004 = { 
	type = character_event
	title = bride_show.0004.t
	desc = bride_show.0004.desc
	theme = realm
	
	right_portrait = { 	
		character = root
		animation = personality_rational
	}
	
	# Let's go!
	option = {
		name = bride_show.0004.a
		custom_tooltip = bride_show.0004.a.tt

		if = {
			limit = {
				NOT = {
					exists = scope:liege
				}
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
		hidden_effect = {
			#Set up lists
			# Vassals
			if = {
				limit = {
					any_in_list = {
						variable = bride_show_subject_list
						any_courtier = {
							bride_show_viable_candidate_trigger = {
								OVERLORD = scope:liege
							} 
						}
						count >= 1
					}
				}
				every_in_list = {
					variable = bride_show_subject_list
					limit = {
						any_courtier = {
							bride_show_viable_candidate_trigger = {
								OVERLORD = scope:liege
							} 
						}
					}
					every_courtier = {
						bride_show_add_to_candidate_list_effect = yes
					}
					if = {
						limit = {
							is_ai = no
						}
						trigger_event = bride_show.1002
					}
				}
			}
			#Let's go!
			bride_show_next_candidate_effect = yes 
		}
		ai_chance = {
			base = 1
		}
	}
}

scripted_effect bride_show_break_betrothal_candidate_effect = {
	if = {
		limit = { exists = betrothed }
		root = { save_scope_as = actor }
		save_scope_as = rejecting_betrothed
		betrothed = {
			save_scope_as = recipient
			scope:recipient = { save_scope_as = rejected_betrothed }
			trigger_event = marriage_interaction.0020
			add_opinion = {
				target = root
				modifier = broke_betrothal_opinion
			}
			every_close_or_extended_family_member = {
				limit = {
					NOR = {
						this = root 
						is_close_or_extended_family_of = root
					}
				}
				custom = all_family_members
				add_opinion = {
					target = root
					modifier = broke_betrothal_opinion
				}
			}
			clear_saved_scope = recipient
		}
		break_betrothal = betrothed
		if = { #Ambitious candidates see this as an opportunity to climb up
			limit = {
				AND = {
					agrees_with_bride_show = yes
					OR = {
						has_trait = greedy
						has_trait = arrogant
						has_trait = ambitious
					}
				}
			}
		}
		else = {
			add_opinion = {
				target = root
				modifier = broke_betrothal_opinion
			}
		}
		every_close_or_extended_family_member = {
			limit = {
				NOR = {
					this = root 
					is_close_or_extended_family_of = root
					AND	= {
						agrees_with_bride_show = yes
						is_vassal_of = root
						has_vassal_stance = courtly
					}
				}
			}
			custom = all_family_members
			add_opinion = {
				target = root
				modifier = broke_betrothal_opinion
			}
		}
	}
}

#List and scopes
scripted_effect bride_show_saved_candidate_effect = {
	remove_from_list = elegible_candidates_list
	add_to_list = presented_candidates_list
	if = {
		limit = { NOT = { exists = scope:candidate_1 } }
		save_scope_as = candidate_1
	}
	else_if = {
		limit = { NOT = { exists = scope:candidate_2 } }
		save_scope_as = candidate_2
	}
	else_if = {
		limit = { NOT = { exists = scope:candidate_3 } }
		save_scope_as = candidate_3
	}
	else = {
		save_scope_as = candidate_4
	}
}

##Pick your candidates##
bride_show.0005 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0005_m_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0005_m_tribal.t
			}
			triggered_desc = {
				trigger = {
					is_female = no
				}
				desc = bride_show.0005_m.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_nomadic
				}
				desc = bride_show.0005_f_nomadic.t
			}
			triggered_desc = {
				trigger = {
					is_female = yes
					government_has_flag = government_is_tribal
				}
				desc = bride_show.0005_f_tribal.t
			}
			desc = bride_show.0005_f.t
		}
	}
	desc = {
		first_valid = { #Intro
			triggered_desc = {
				trigger = {
					OR = {	
						exists = scope:candidate_3
						AND = {
							exists = scope:candidate_2
							can_have_four_candidates_trigger = no
						}
					}
				}
				desc = bride_show.0005.start_3.desc
			}
			triggered_desc = {
				trigger = {
					OR = {	
						exists = scope:candidate_1
						AND = {
							exists = scope:candidate_2
							can_have_four_candidates_trigger = yes
						}
					}
				}
				desc = bride_show.0005.start_2.desc
			}
			triggered_desc = {
				desc = bride_show.0005.start.desc
			}
		}
		first_valid = { #Traits
			triggered_desc = {
				trigger = { #2 #4
					OR = {
						AND = {	
							exists = scope:candidate_1
							NOT = {
								exists = scope:candidate_2
							}
						}
						AND = {
							exists = scope:candidate_3
							NOT = {
								exists = scope:candidate_4
							}
						}
					}
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = shy
								has_trait = paranoid
								has_trait = craven
							}
							NOR = {
								has_trait = ambitious
								has_trait = brave
								has_trait = arrogant
							}
						}
					}
				}
				desc = bride_show.0005.shy_2.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = shy
								has_trait = paranoid
								has_trait = craven
							}
							NOR = {
								has_trait = ambitious
								has_trait = brave
								has_trait = arrogant
							}
						}
					}
				}
				desc = bride_show.0005.shy.desc
			}
			triggered_desc = {
				trigger = { #2 #4
					OR = {
						AND = {	
							exists = scope:candidate_1
							NOT = {
								exists = scope:candidate_2
							}
						}
						AND = {
							exists = scope:candidate_3
							NOT = {
								exists = scope:candidate_4
							}
						}
					}
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = brave
								has_trait = ambitious
							}
							NOR = {
								has_trait = craven
								has_trait = paranoid
								has_trait = shy
								has_trait = arrogant
							}
						}
					}
				}
				desc = bride_show.0005.brave_2.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = brave
								has_trait = ambitious
							}
							NOR = {
								has_trait = craven
								has_trait = paranoid
								has_trait = shy
								has_trait = arrogant
							}
						}
					}
				}
				desc = bride_show.0005.brave.desc
			}
			triggered_desc = {
				trigger = { #2 #4
					OR = {
						AND = {	
							exists = scope:candidate_1
							NOT = {
								exists = scope:candidate_2
							}
						}
						AND = {
							exists = scope:candidate_3
							NOT = {
								exists = scope:candidate_4
							}
						}
					}
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = arrogant
							}
							NOR = {
								has_trait = craven
								has_trait = paranoid
								has_trait = shy
								has_trait = brave
								has_trait = ambitious
							}
						}
					}
				}
				desc = bride_show.0005.arrogant_2.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							OR = {
								has_trait = arrogant
							}
							NOR = {
								has_trait = craven
								has_trait = paranoid
								has_trait = shy
								has_trait = brave
								has_trait = ambitious
							}
						}
					}
				}
				desc = bride_show.0005.arrogant.desc
			}
			triggered_desc = {
				trigger = { #2 #4
					OR = {
						AND = {	
							exists = scope:candidate_1
							NOT = {
								exists = scope:candidate_2
							}
						}
						AND = {
							exists = scope:candidate_3
							NOT = {
								exists = scope:candidate_4
							}
						}
					}
				}
				desc = bride_show.0005.generic_1_2.desc
			}
			triggered_desc = {
				desc = bride_show.0005.generic_1.desc
			}
		}
		first_valid = { #Beauty
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = beauty_good_3
					}
				}
				desc = bride_show.0005.beautiful.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = beauty_good_2
					}
				}
				desc = bride_show.0005.handsome.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = beauty_good_1
					}
				}
				desc = bride_show.0005.comely.desc
			}
			triggered_desc = {
				desc = bride_show.0005.generic_2.desc
			}
		}
		first_valid = { #Intellect
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = intellect_good_3
					}
				}
				desc = bride_show.0005.genius.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = intellect_good_2
					}
				}
				desc = bride_show.0005.intelligent.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						has_trait = intellect_good_1
					}
				}
				desc = bride_show.0005.quick.desc
			}
			triggered_desc = {
				desc = bride_show.0005.generic_3.desc
			}
		}
		first_valid = { #Skills
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							diplomacy <= 11
							learning <= 11
							stewardship >= 12
						}
					}
				}
				desc = bride_show.0005.stewardship.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							diplomacy <= 11
							learning >= 12
							stewardship <= 11
						}
					}
				}
				desc = bride_show.0005.learning.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						AND = {
							diplomacy >= 12
							learning <= 11
							stewardship <= 11
						}
					}
				}
				desc = bride_show.0005.diplomacy.desc
			}
			triggered_desc = {
				trigger = {
					scope:potential_candidate = {
						OR = {
							AND = {
								stewardship >= 12
								learning >= 12
							}
							AND = {
								stewardship >= 12
								diplomacy >= 12
							}
							AND = {
								learning >= 12
								diplomacy >= 12
							}
						}
					}
				}
				desc = bride_show.0005.multiple.desc
			}
			triggered_desc = {
				desc = bride_show.0005.generic_4.desc
			}
		}
		desc = bride_show.0005.end.desc
	}
	theme = realm
	
	left_portrait = {
		character = scope:potential_candidate
		animation = flirtation
	}
	lower_center_portrait = {
		trigger = {
			scope:pc_court_owner ?= scope:potential_candidate.court_owner
		}
		character = scope:pc_court_owner
	}

	immediate = {
		if = {
			limit = {
				NOT = {
					exists = scope:liege
				}
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
		scope:potential_candidate.court_owner ?= {
			save_scope_as = pc_court_owner
		}
	}
	
	# Marry them
	option = {
		name = bride_show.0005.a
		trigger = {
			allowed_more_spouses = yes
			scope:potential_candidate = {
				age >= 16
				could_marry_character_trigger = { CHARACTER = scope:liege }
			}
			age >= 16
			gold >= bride_compensation_payment_value
		}
		show_as_unavailable = { 
			NOT = { gold >= bride_compensation_payment_value }
			allowed_more_spouses = yes
			scope:potential_candidate = {
				age >= 16
				could_marry_character_trigger = { CHARACTER = scope:liege }
			}
			age >= 16
		}
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= bride_compensation_payment_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}

		save_scope_value_as = {
			name = gold_to_pay
			value = bride_compensation_payment_value
		}
		#Reward
		if = {
			limit = {
				exists = scope:potential_candidate.court_owner
			}
			pay_short_term_gold = {
				target = scope:potential_candidate.court_owner
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate = {
				save_scope_as = candidate_marriage
				court_owner = {
					if = {
						limit = {
							any_close_family_member = {
								this = scope:candidate_marriage
							}
							is_ai = no
						}
						trigger_event = bride_show.0008
					}
					else = {
						hidden_effect = {
							send_interface_toast = {
								type = event_generic_neutral
								title = chosen_consort_t
								right_icon = scope:liege
								left_icon = scope:potential_candidate
								custom_tooltip = chosen_spouse_d
								

								scope:liege = { 
									show_as_tooltip = {
										pay_short_term_gold = {
											target = scope:potential_candidate.court_owner
											gold = bride_compensation_payment_value
										}
									}
									if = {
										limit  ={
											any_close_family_member = {
												this = scope:candidate_marriage
											}
										}
										#Prestige
										if = {
											limit = {
												highest_held_title_tier = tier_duchy
											}
											scope:potential_candidate.court_owner = {
												add_prestige = miniscule_prestige_value
											}
										}
										else_if = {
											limit = {
												highest_held_title_tier = tier_kingdom
											}
											scope:potential_candidate.court_owner = {
												add_prestige = minor_prestige_value
											}
										}
										else_if = {
											limit = {
												highest_held_title_tier >= tier_empire
											}
											scope:potential_candidate.court_owner = {
												add_prestige = medium_prestige_value
											}
										}
									}
								}

								gain_influence_harem_politics_effect = {
									RECIPIENT = scope:potential_candidate.court_owner
									CHARACTER = scope:liege
									TARGET = scope:potential_candidate
								}
							}
						}
					}
				}
			}
			
			#Courtly vassals get a positive opinion
			if = {
				limit = {
					scope:potential_candidate.court_owner = {
						is_vassal_of = root
						has_vassal_stance = courtly
						any_close_family_member = {
							this = scope:potential_candidate
						}
						agrees_with_bride_show = yes
					}
				}
				scope:potential_candidate.court_owner = {
					add_opinion = {
						target = root
						modifier = courtly_vassal_marriage_opinion
					}
				}
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:potential_candidate
				gold = bride_compensation_payment_value
			}
			if = {
				limit = {
					highest_held_title_tier = tier_duchy
				}
				scope:potential_candidate = {
					add_prestige = miniscule_prestige_value
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier = tier_kingdom
				}
				scope:potential_candidate = {
					add_prestige = minor_prestige_value
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier = tier_empire
				}
				scope:potential_candidate = {
					add_prestige = medium_prestige_value
				}
			}
		}
		
		stress_impact = {
			paranoid = miniscule_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		
		scope:potential_candidate = {
			bride_show_saved_candidate_effect = yes
			bride_show_break_betrothal_candidate_effect = yes
			hidden_effect = {
				if = {
					limit = {
						is_hostage = yes
					}
					return_hostage = yes
				}
			}
			save_scope_as = secondary_recipient
		}
		if = {
			limit = {
				is_female = yes
			}
			marry_matrilineal = scope:potential_candidate
		}
		else = {
			marry = scope:potential_candidate
		}
		
		#Marriage effects
		save_scope_as = actor
		save_scope_as = recipient
		save_scope_as = secondary_actor
		marriage_interaction_on_accept_effect = yes
		
		ai_chance = {
			base = 10
			modifier = { #Weigh down for stress
				add = -25
				has_trait = paranoid
			}
			modifier = { #Weigh down for stress
				add = -15
				has_trait = craven
			}
			modifier = { #Weigh down for stress
				add = -25
				has_trait = shy
			}
			modifier = { #More likely if root is lustful
				add = 15
				has_trait = lustful
			}
			modifier = { #More likely if concubinage isn't accepted
				add = 20
				allowed_concubines = no
			}
			modifier = { #Less likely if the candidate is a commoner
				add = -20
				can_have_settled_harem_trigger = yes
				scope:potential_candidate = {
					is_lowborn = yes
				}
			}
			modifier = { #More likely if root doesn't have enough spouses
				add = 50
				scope:liege = {
					trigger_if = {
						limit = {
							primary_title.tier >= 5
						}
						any_spouse = {
							count < 4
						}
					}
					trigger_else_if = {
						limit = {
							primary_title.tier >= 4
						}
						any_spouse = {
							count < 3
						}
					}
					trigger_else_if = {
						limit = {
							primary_title.tier >= 3
						}
						any_spouse = {
							count < 2
						}
					}
					trigger_else = {
						any_spouse = {
							count < 1
						}
					}
				}
			}
			modifier = { #Less likely if the candidate is lowborn and low legitimacy
				add = -60
				OR = {
					AND = {
						highest_held_title_tier = tier_empire
						legitimacy_level <= 3
					}
					AND = {
						highest_held_title_tier = tier_kingdom
						legitimacy_level <= 2
					}
					AND = {
						highest_held_title_tier = tier_duchy
						legitimacy_level <= 1
					}
				}
				scope:potential_candidate = {
					is_lowborn = yes
				}
				can_have_settled_harem_trigger = yes
			}
			modifier = { #More likely if the shares same faith
				scope:potential_candidate.faith = root.faith
				add = 10
			}
			modifier = { #More likely if the shares same culture
				scope:potential_candidate.culture = root.culture
				add = 10
			}
			modifier = { #More likely if the candidate is the child of a vassal
				add = 35
				scope:potential_candidate = {
					any_close_family_member = { is_vassal_of = root }
				}
			}
			modifier = { #More likely if the candidate is the child of a powerful vassal
				add = 40
				scope:potential_candidate = {
					any_close_family_member = { 
						OR = {
							is_powerful_vassal_of = root
							is_councillor_of = root
						}
					}
				}
			}
			modifier = {
				government_has_flag = government_is_administrative
				scope:potential_candidate = {
					any_close_family_member = {
						government_has_flag = government_is_administrative
						top_liege ?= scope:liege
						house ?= {
							is_dominant_family = yes
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:potential_candidate = {
					any_close_family_member = {
						tier_difference = {
							target = scope:liege
							value >= -1
						}
					}
				}
				add = 15
			}
			modifier = { #More likely if the candidate doesn't have the trait child of a concubine
				add = 10
				scope:potential_candidate = {
					NOR = {
						has_trait = child_of_concubine_female
						has_trait = child_of_concubine_male
						has_trait = wild_oat
						has_trait = bastard
					}
				}
			}
			modifier = { #More likely if the candidate has nice traits
				add = 10
				scope:potential_candidate = {
					OR = {
						has_trait = beauty_good_1
						has_trait = physique_good_1
						has_trait = intellect_good_1
					}
				}
			}
			modifier = { #More likely if the candidate has good traits
				add = 20
				scope:potential_candidate = {
					OR = {
						has_trait = beauty_good_2
						has_trait = physique_good_2
						has_trait = intellect_good_2
					}
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 30
				scope:potential_candidate = {
					OR = {
						has_trait = beauty_good_3
						has_trait = physique_good_3
						has_trait = intellect_good_3
					}
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 15
				scope:potential_candidate = {
					has_trait = pure_blooded
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 40
				scope:potential_candidate = {
					has_trait = golden_lineage
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 40
				faith.religion = religion:islam_religion
				scope:potential_candidate = {
					has_trait = sayyid
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 40
				faith.religion = religion:zoroastrianism_religion
				scope:potential_candidate = {
					has_trait = saoshyant
				}
			}
			modifier = { #More likely if the candidate is virtuous
				add = 10
				scope:potential_candidate = {
					num_sinful_traits = 0
				}
			}
			modifier = { #More likely if the candidate is virtuous
				add = {
					value = 10
					if = {
						limit = {
							num_virtuous_traits >= 2
						}
						add = 10
					}
				}
				scope:potential_candidate = {
					num_virtuous_traits >= 1
				}
			}
			modifier = { #More likely if the candidate isn't a criminal
				add = 10
				NOT = { has_imprisonment_reason = scope:potential_candidate }
			}
			modifier = { #More likely if root doesn't have kids
				add = 15
				is_virgin_trigger = yes
			}
			modifier = { #More likely if candidate has good skills
				add = 10
				scope:potential_candidate = {
					OR = { 
						stewardship >= 9
						learning >= 9
					}
				}
			}
			modifier = { #More likely if candidate has good skills
				add = 5
				scope:potential_candidate = {
					OR = { 
						stewardship >= 13
						learning >= 13
					}
				}
			}
			modifier = { #More likely if candidate has good skills
				add = 5
				scope:potential_candidate = {
					OR = { 
						stewardship >= 17
						learning >= 17
					}
				}
			}
			compatibility_modifier = { #Trait compatibility
				who = root
				compatibility_target = scope:potential_candidate
				min = -25
				max = 25
				multiplier = 1
			}
		}
	}

	#Make them my concubine
	option = {
		name = bride_show.0005.b
		trigger = {
			allowed_concubines = yes
			allowed_more_concubines = yes
			scope:potential_candidate = {
				age >= 16
				could_marry_character_trigger = { CHARACTER = scope:liege }
			}
			age >= 16
			gold >= bride_compensation_payment_value
		}
		show_as_unavailable = {
			NOT = { gold >= bride_compensation_payment_value }
			allowed_concubines = yes
			allowed_more_concubines = yes
			scope:potential_candidate = {
				age >= 16
				could_marry_character_trigger = { CHARACTER = scope:liege }
			}
			age >= 16
		}
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= bride_compensation_payment_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}
		
		save_scope_value_as = {
			name = gold_to_pay
			value = bride_compensation_payment_value
		}
		#Reward
		if = {
			limit = {
				exists = scope:potential_candidate.court_owner
			}
			pay_short_term_gold = {
				target = scope:potential_candidate.court_owner
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate = {
				save_scope_as = candidate_concubinage
				court_owner = {
					if = {
						limit = {
							any_close_family_member = {
								this = scope:candidate_concubinage
							}
							is_ai = no
						}
						trigger_event = bride_show.0008
					}
					else = {
						hidden_effect = {
							send_interface_toast = {
								type = event_generic_neutral
								title = chosen_consort_t
								right_icon = scope:liege
								left_icon = scope:potential_candidate
								custom_tooltip = chosen_concubine_d
								

								scope:liege = { 
									show_as_tooltip = {
										pay_short_term_gold = {
											target = scope:potential_candidate.court_owner
											gold = bride_compensation_payment_value
										}
									}
									if = {
										limit  ={
											any_close_family_member = {
												this = scope:candidate_concubinage
											}
										}
										#Prestige
										if = {
											limit = {
												highest_held_title_tier = tier_kingdom
											}
											scope:potential_candidate.court_owner = {
												add_prestige = miniscule_prestige_value
											}
										}
										else_if = {
											limit = {
												highest_held_title_tier >= tier_empire
											}
											scope:potential_candidate.court_owner = {
												add_prestige = minor_prestige_value
											}
										}
									}
								}

								gain_influence_harem_politics_effect = {
									RECIPIENT = scope:potential_candidate.court_owner
									CHARACTER = scope:liege
									TARGET = scope:potential_candidate
								}
							}
						}
					}
				}
			}
			
			#Courtly vassals get a positive opinion
			if = {
				limit = {
					scope:potential_candidate.court_owner = {
						is_vassal_of = root
						has_vassal_stance = courtly
						any_close_family_member = {
							this = scope:potential_candidate
						}
						agrees_with_bride_show = yes
					}
				}
				scope:potential_candidate.court_owner = {
					add_opinion = {
						target = root
						modifier = courtly_vassal_marriage_opinion
					}
				}
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:potential_candidate
				gold = bride_compensation_payment_value
			}
			if = {
				limit = {
					highest_held_title_tier = tier_kingdom
				}
				scope:potential_candidate = {
					add_prestige = miniscule_prestige_value
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier = tier_empire
				}
				scope:potential_candidate = {
					add_prestige = minor_prestige_value
				}
			}
		}
		
		stress_impact = {
			paranoid = miniscule_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		
		scope:potential_candidate = {
			bride_show_saved_candidate_effect = yes
			bride_show_break_betrothal_candidate_effect = yes
			hidden_effect = {
				if = {
					limit = {
						is_hostage = yes
					}
					return_hostage = yes
				}
			}
			save_scope_as = recipient
			save_scope_as = secondary_recipient
		}
		save_scope_as = actor
		save_scope_as = secondary_actor
		
		#Concubinage effects
		concubine_on_accept_effect = yes
		make_concubine = scope:recipient
		
		ai_chance = {
			base = 45
			modifier = { #Weigh down for stress
				add = -25
				has_trait = paranoid
			}
			modifier = { #Weigh down for stress
				add = -15
				has_trait = craven
			}
			modifier = { #Weigh down for stress
				add = -25
				has_trait = shy
			}
			modifier = { #More likely if root is lustful
				add = 20
				has_trait = lustful
			}

			modifier = { #More likely if root doesn't have enough spouses
				add = 15
				number_of_concubines < number_of_desired_concubines
			}

			modifier = { #More likely if the shares same faith
				scope:potential_candidate.faith = root.faith
				add = 10
			}
			modifier = { #More likely if the shares same culture
				scope:potential_candidate.culture = root.culture
				add = 10
			}

			modifier = { #More likely if the candidate is the child of a vassal
				add = 5
				scope:potential_candidate = {
					any_close_family_member = { is_vassal_of = root }
				}
			}
			modifier = { #More likely if the candidate is the child of a powerful vassal
				add = 10
				scope:potential_candidate = {
					any_close_family_member = { 
						OR = {
							is_powerful_vassal_of = root
							is_councillor_of = root
						}
					}
				}
			}
			modifier = {
				government_has_flag = government_is_administrative
				scope:potential_candidate = {
					any_close_family_member = {
						government_has_flag = government_is_administrative
						top_liege ?= scope:liege
						house ?= {
							is_dominant_family = yes
						}
					}
				}
				add = 15
			}
			modifier = {
				scope:potential_candidate = {
					any_close_family_member = {
						tier_difference = {
							target = scope:liege
							value >= -1
						}
					}
				}
				add = 5
			}

			modifier = { # Beauty
				add = 10
				scope:potential_candidate = {
					has_trait = beauty_good_1
				}
			}
			modifier = { # Beauty
				add = 15
				scope:potential_candidate = {
					has_trait = beauty_good_2
				}
			}
			modifier = { # Beauty
				add = 20
				scope:potential_candidate = {
					has_trait = beauty_good_3
				}
			}

			modifier = { # Physique
				add = 5
				scope:potential_candidate = {
					has_trait = physique_good_1
				}
			}
			modifier = { # Physique
				add = 10
				scope:potential_candidate = {
					has_trait = physique_good_2
				}
			}
			modifier = { # Physique
				add = 15
				scope:potential_candidate = {
					has_trait = physique_good_3
				}
			}

			modifier = { # Intellect
				add = 5
				scope:potential_candidate = {
					has_trait = intellect_good_1
				}
			}
			modifier = { # Intellect
				add = 10
				scope:potential_candidate = {
					OR = {
						has_trait = intellect_good_2
						has_trait = intellect_good_3
					}
				}
			}

			modifier = { #More likely if the candidate has excellent traits
				add = 15
				scope:potential_candidate = {
					has_trait = pure_blooded
				}
			}
			modifier = { #More likely if the candidate has excellent traits
				add = 40
				scope:potential_candidate = {
					has_trait = golden_lineage
				}
			}
			modifier = { #More likely if the candidate is virtuous
				add = 10
				scope:potential_candidate = {
					num_sinful_traits = 0
				}
			}
			modifier = { #More likely if the candidate is virtuous
				add = {
					value = 10
					if = {
						limit = {
							num_virtuous_traits >= 2
						}
						add = 10
					}
				}
				scope:potential_candidate = {
					num_virtuous_traits >= 1
				}
			}
			modifier = { #More likely if the candidate isn't a criminal
				add = 5
				NOT = { has_imprisonment_reason = scope:potential_candidate }
			}
			modifier = { #More likely if root doesn't have kids
				add = 20
				is_virgin_trigger = yes
			}
			modifier = { #More likely if candidate has good skills
				add = 15
				scope:potential_candidate = {
					OR = {
						learning >= 9
						diplomacy >= 9
					}
				}
			}
			modifier = { #More likely if candidate has good skills
				add = 5
				scope:potential_candidate = {
					OR = {
						learning >= 13
						diplomacy >= 13
					}
				}
			}
			modifier = { #More likely if candidate has good skills
				add = 5
				scope:potential_candidate = {
					OR = {
						learning >= 17
						diplomacy >= 17
					}
				}
			}
			compatibility_modifier = { #Trait compatibility
				who = root
				compatibility_target = scope:potential_candidate
				min = -50
				max = 50
				multiplier = 2
			}
			modifier = { #Less likely if they could inherit a title
				add = -20
				scope:potential_candidate = {
					any_heir_title = {
						place_in_line_of_succession = {
							target = prev
							value <= 2
						}
					}
				}
			}
		}
	}

	#Recruit to court
	option = { # Recruit to court and break betrothal
		name = bride_show.0005.c
		if = {
			limit = {
				scope:potential_candidate = {
					exists = betrothed
				}
			}
			custom_tooltip = bride_show.0005.c.tt
		}
		trigger = {
			scope:potential_candidate = {
				age >= 16
			}
			gold >= bride_compensation_payment_value
		}
		show_as_unavailable = { 
			scope:potential_candidate = {
				age >= 16
			}
			NOT = { gold >= bride_compensation_payment_value } 
		}
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= bride_compensation_payment_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}
		
		save_scope_value_as = {
			name = gold_to_pay
			value = bride_compensation_payment_value
		}
		#Reward
		if = {
			limit = {
				exists = scope:potential_candidate.court_owner
			}
			pay_short_term_gold = {
				target = scope:potential_candidate.court_owner
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate = {
				save_scope_as = candidate_courtier
				court_owner = {
					if = {
						limit = {
							any_close_family_member = {
								this = scope:candidate_courtier
							}
							is_ai = no
						}
						trigger_event = bride_show.0008
					}
					else = {
						hidden_effect = {
							send_interface_toast = {
								type = event_generic_neutral
								title = chosen_candidate_t
								right_icon = scope:liege
								left_icon = scope:potential_candidate
								custom_tooltip = chosen_courtier_d
								
								show_as_tooltip = {
									scope:liege = { 
										pay_short_term_gold = {
											target = scope:potential_candidate.court_owner
											gold = bride_compensation_payment_value
										}
									}
								}
								#Prestige
								if = {
									limit = {
										any_close_family_member = {
											this = scope:potential_candidate
										}
									}
									add_prestige = miniscule_prestige_value
								}
								gain_influence_harem_politics_effect = {
									RECIPIENT = scope:potential_candidate.court_owner
									CHARACTER = scope:liege
									TARGET = scope:potential_candidate
								}
							}
						}
					}
				}
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:potential_candidate
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate = {
				add_prestige = miniscule_prestige_value
			}
		}
		
		stress_impact = {
			paranoid = miniscule_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		
		scope:potential_candidate = {
			bride_show_saved_candidate_effect = yes
			bride_show_break_betrothal_candidate_effect = yes
		}
		hidden_effect = {
			if = {
				limit = {
					scope:potential_candidate = {
						is_hostage = yes
					}
				}
				scope:potential_candidate = {
					return_hostage = yes
				}
			}
		}
		add_courtier = scope:potential_candidate
		scope:potential_candidate = {
			hidden_effect = {
				return_to_court = yes
			}
		}
		
		ai_chance = {
			base = 0
		}
	}

	#Break betrothal for kids
	option = { # I've got plans for you
		name = bride_show.0005.d
		trigger = {
			scope:potential_candidate = {
				age <= 15
			}
			gold >= bride_compensation_payment_value
		}
		show_as_unavailable = {
			scope:potential_candidate = {
				age <= 15
			}
			NOT = { gold >= bride_compensation_payment_value } 
		}
		flavor = { #To get warning if you don't have enough money
			triggered_desc = {
				trigger = {
					NOT = { gold >= bride_compensation_payment_value }
				}
				desc = holy_order.0202.a._not.tt
			}
		}
		
		save_scope_value_as = {
			name = gold_to_pay
			value = bride_compensation_payment_value
		}
		#Reward
		if = {
			limit = {
				exists = scope:potential_candidate.court_owner
			}
			pay_short_term_gold = {
				target = scope:potential_candidate.court_owner
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate.court_owner = {
				if = {
					limit = {
						any_close_family_member = {
							this = scope:potential_candidate
						}
						is_ai = no
					}
					trigger_event = bride_show.0008
				}
				else = {
					hidden_effect = {
						send_interface_toast = {
							type = event_generic_neutral
							title = chosen_candidate_t
							right_icon = scope:liege
							left_icon = scope:potential_candidate
							custom_tooltip = broken_betrothal_d
							if = {
								limit = {
									is_vassal_of = root
									has_vassal_stance = courtly
									any_close_family_member = {
										this = scope:potential_candidate
									}
									agrees_with_bride_show = yes
								}
								add_prestige = miniscule_prestige_value
							}
							show_as_tooltip = {
								scope:liege = { 
									pay_short_term_gold = {
										target = scope:potential_candidate.court_owner
										gold = bride_compensation_payment_value
									}
								}
							}
						}
					}
				}
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:potential_candidate
				gold = bride_compensation_payment_value
			}
			scope:potential_candidate = {
				add_prestige = miniscule_prestige_value
			}
		}
		
		scope:potential_candidate = {
			bride_show_saved_candidate_effect = yes
			bride_show_break_betrothal_candidate_effect = yes
		}
		
		ai_chance = {
			base = 0
		}
	}

	# Pass
	option = {
		name = bride_show.0005.e
		if = {
			limit = { 
				OR = {
					AND = {	
						exists = scope:candidate_2 
						can_have_four_candidates_trigger = no
					}
					exists = scope:candidate_3
				}
			}
			custom_tooltip = bride_show.0005.e_last.tt
		}
		else  = {
			custom_tooltip = bride_show.0005.e.tt
		}
		
		if = {
			limit = {
				exists = scope:potential_candidate.court_owner
				scope:potential_candidate.court_owner = {
					AND = {
						is_vassal_of = root
						has_vassal_stance = courtly
						any_close_family_member = {
							this = scope:potential_candidate
						}
						agrees_with_bride_show = yes
					}
				}
			}
			scope:potential_candidate.court_owner = {
				add_opinion = {
					target = root
					modifier = courtly_vassal_rejected_opinion
				}
			}
		}
		
		scope:potential_candidate = {
			bride_show_saved_candidate_effect = yes
			add_character_flag = {
				flag = rejected_candidate_flag
				days = 5
			}
			if = {
				limit = {
					NOR = {
						has_trait = paranoid
						has_trait = craven
						has_trait = shy
						has_trait = chaste
						has_trait = celibate
					}
					is_betrothed = no
					agrees_with_bride_show = yes
				}
				add_opinion = {
					target = root
					modifier = rejected_me_opinion
				}
			}
			else_if = {
				limit = {
					AND = {
						OR = {
							has_trait = arrogant
							has_trait = greedy
							has_trait = ambitious
						}
						agrees_with_bride_show = yes
					}
				}
				add_opinion = {
					target = root
					modifier = rejected_me_opinion
				}
			}
		}
		ai_chance = {
			base = 15
			modifier = { #Paranoid
				add = 20
				has_trait = paranoid
			}
			modifier = { #Shy
				add = 20
				has_trait = shy
			}
			modifier = { #Craven
				add = 10
				has_trait = craven
			}
			modifier = { #More likely if the candidate is not the child of a vassal
				add = 30
				scope:potential_candidate = {
					NOT = {
						any_close_family_member = { 
							is_vassal_of = root 
						}
					}
				}
			}
			modifier = { #More likely if the candidate doesn't have any good traits
				add = 15
				scope:potential_candidate = {
					NOR = {
						has_trait = beauty_good
						has_trait = intellect_good
						has_trait = physique_good
						has_trait = fecund
					}
				}
			}
			modifier = { #More likely if candidate has bad skills
				add = 15
				scope:potential_candidate = {
					NOR = {
						learning >= medium_skill_rating
						diplomacy >= medium_skill_rating
						martial >= medium_skill_rating
						stewardship >= medium_skill_rating
						intrigue >= medium_skill_rating
						prowess >= medium_skill_rating
					}
				}
			}
			modifier = {
				scope:potential_candidate = {
					num_of_bad_genetic_traits >= 1
				}
				add = {
					value = 25
					if = {
						limit = {
							num_of_bad_genetic_traits >= 2
						}
						add = 10
					}
				}
			}
		}
	}
	
	after = {
		if = {
			limit = {
				exists = scope:pc_court_owner
			}
			clear_saved_scope = pc_court_owner
		}
		hidden_effect = {
			bride_show_next_candidate_effect = yes
		}
	}

}

bride_show.0006 = {
	type = character_event
	title = bride_show.0006.t
	desc = bride_show.0006.desc

	theme = realm
	
	right_portrait = { 	
		character = root
		animation = personality_honorable
	}
	left_portrait = { 	
		character = scope:candidate_1
		animation = personality_compassionate
	}
	lower_left_portrait = { 	
		character = scope:candidate_2
	}
	lower_center_portrait = { 	
		trigger = {
			exists = scope:candidate_4
		}
		character = scope:candidate_4
	}
	lower_right_portrait = { 	
		character = scope:candidate_3
	}

	immediate = {
	}
	
	option = {
		name = bride_show.0006.a
		if = {
			limit = {
				is_valid_for_legitimacy_change = yes
			}
			add_legitimacy = miniscule_legitimacy_gain
		}
		
		hidden_effect = {
			if = {
				limit = {
					any_in_list = {
						list = created_candidates_list
						has_character_flag = created_bride_flag
						count >= 1
					}
				}
				every_in_list = {
					list = created_candidates_list
					if = {
						limit = {
							has_character_flag = created_bride_flag
						}
						if = {
							limit = {
								NOT = {
									exists = court_owner
								}
								has_character_flag = rejected_candidate_flag
							}
							death = {
								death_reason = death_vanished
							}
						}
						else = {
							remove_character_flag = created_bride_flag
						}
					}
				}
			}
			if = {
				limit = {
					any_in_list = {
						variable = bride_show_subject_list
						count >= 1
					}
				}
				clear_variable_list = bride_show_subject_list
			}
			if = {
				limit = {
					has_variable = beauty_important
				}
				remove_variable = beauty_important
			}
			if = {
				limit = {
					has_variable = family_background_important
				}
				remove_variable = family_background_important
			}
			if = {
				limit = {
					has_variable = personality_skills_important
				}
				remove_variable = personality_skills_important
			}
			random_list = {
				50 = {
					modifier = { # Traits
						add = 10
						has_trait = lustful
					}
					modifier = { # Traits
						add = 10
						has_trait = deviant
					}
					modifier = { # Traits
						add = 10
						has_trait = rakish
					}
					modifier = { # Tier
						add = 10
						highest_held_title_tier >= tier_kingdom
					}
					modifier = { # Consorts
						add = 10
						any_consort = {
							count >= 5
						}
					}
					trigger_event = {
						id = harem_politics.0011
						days = { 7 20 }
					}
				}
				50 = { #Nothing
					modifier = { # Traits
						add = 10
						has_trait = chaste
					}
					modifier = { # Traits
						add = 10
						has_trait = celibate
					}
					modifier = { # Traits
						add = 15
						has_trait = shy
					}
				}
				15 = {
					modifier = { # Traits
						add = 10
						has_trait = lustful
					}
					modifier = { # Traits
						add = 10
						has_trait = deviant
					}
					modifier = { # Traits
						add = 10
						has_trait = rakish
					}
					modifier = { # Tier
						add = 10
						highest_held_title_tier >= tier_duchy
					}
					modifier = { # Consorts
						add = 10
						any_consort = {
							count >= 5
						}
					}
					trigger_event = {
						id = harem_politics.0016
						days = { 7 20 }
					}
				}
			}
		}
		ai_chance = {
			base = 15
		}
	}
}

#############################
##Announcing the Bride Show##
#############################
bride_show.0007 = {
	type = letter_event
	opening = {
		first_valid = {
			triggered_desc = { #Imperial decree
			    trigger = {
					scope:liege = {
						highest_held_title_tier = tier_empire
					}
				}
				desc = bride_show.imperial.desc
			}
			triggered_desc = { #Royal decree
			    trigger = {
					scope:liege = {
						highest_held_title_tier = tier_kingdom
					}
				}
				desc = bride_show.royal.desc
			}
			triggered_desc = { #Princely decree
			    trigger = {
					scope:liege = {
						any_parent = {
							highest_held_title_tier >= tier_kingdom
						}
					}
				}
				desc = bride_show.princely.desc
			}
			desc = bride_show.noble.desc
		}
	}
	desc = {
		first_valid = {
			triggered_desc = { #Vassals
				trigger = {
					is_vassal_of = scope:liege
				}
				desc = bride_show.0007.start_vassal.desc
			}
			#Tributaries
			desc = bride_show.0007.start_tributary.desc
		}
		desc = bride_show.0007.desc.request
		first_valid = {
			triggered_desc = { #Vassal
				trigger = {
					is_vassal_of = scope:liege
				}
				desc = bride_show.0007.end_vassal.desc
			}
			#Tributary
			desc = bride_show.0007.end_tributary.desc
		}
	}
	sender = scope:liege

	trigger = {
		harem_politics_is_valid_bride_show_subject_trigger = {
			OVERLORD = scope:liege
		}
		any_courtier = {
			bride_show_viable_candidate_trigger = {
				OVERLORD = scope:liege
			} 
		}
	}

	immediate = {
		save_scope_as = subject_scope
		if = {
			limit = {
				is_vassal_of = scope:liege
			}
			if = {
				limit = {
					OR = { 
						culture = { has_cultural_tradition = tradition_ep3_palace_politics }
						culture = { has_cultural_tradition = tradition_legalistic }
						hp_accepts_concubinage = yes
						hp_accepts_polygamy = yes
					}
				}
				if = {
					limit = {
						has_vassal_stance = courtly
					}
					add_opinion = {
						target = scope:liege
						modifier = bride_show_vassal_opinion
						opinion = 5
					}
				}
				else = {
					add_opinion = {
						target = scope:liege
						modifier = bride_show_vassal_opinion
						opinion = -10
					}
				}
			}
			else_if = {
				limit = {
					NOR = { 
						culture = { has_cultural_tradition = tradition_ep3_palace_politics }
						culture = { has_cultural_tradition = tradition_legalistic }
						hp_accepts_concubinage = yes
						hp_accepts_polygamy = yes
					}
				}
				add_opinion = {
					target = scope:liege
					modifier = bride_show_vassal_opinion
					opinion = -20
				}
			}
		}
		else = {
			if = {
				limit = {
					OR = { 
						culture = { has_cultural_tradition = tradition_ep3_palace_politics }
						culture = { has_cultural_tradition = tradition_legalistic }
						hp_accepts_concubinage = yes
						hp_accepts_polygamy = yes
					}
				}
				add_opinion = {
					target = scope:liege
					modifier = bride_show_vassal_opinion
					opinion = -20
				}
			}
			else_if = {
				limit = {
					NOR = { 
						culture = { has_cultural_tradition = tradition_ep3_palace_politics }
						culture = { has_cultural_tradition = tradition_legalistic }
						hp_accepts_concubinage = yes
						hp_accepts_polygamy = yes
					}
				}
				add_opinion = {
					target = scope:liege
					modifier = bride_show_vassal_opinion
					opinion = -30
				}
			}
		}
	}

	#There's nothing I can do
	option = {
		name = bride_show.0007.a
		trigger = {
			is_vassal_of = scope:liege
		}
		scope:liege = {
			add_to_variable_list = {
				name = bride_show_subject_list
				target = root
				days = 10
			}
		}
		ai_chance = {
			base = 1
		}
	}
	#I shall accept it
	option = {
		name = bride_show.0007.b
		trigger = {
			NOT = {
				is_vassal_of = scope:liege
			}
		}
		# Accepting it is akin to being treated as a vassal
		add_prestige = medium_prestige_loss
		scope:liege = {
			hidden_effect = {
				if = {
					limit = {
						is_ai = no
					}
					send_interface_toast = {
						type = event_generic_good
						title = bride_show.0007.b.t
						right_icon = root
						custom_tooltip = bride_show.0007.b.desc
						if = {
							limit = {
								root.highest_held_title_tier >= tier_empire
							}
							add_prestige = medium_prestige_value
						}
						else_if = {
							limit = {
								root.highest_held_title_tier = tier_kingdom
							}
							add_prestige = minor_prestige_value
						}
					}
				}
				else = {
					if = {
						limit = {
							root.highest_held_title_tier >= tier_empire
						}
						add_prestige = medium_prestige_value
					}
					else_if = {
						limit = {
							root.highest_held_title_tier = tier_kingdom
						}
						add_prestige = minor_prestige_value
					}
				}
				add_to_variable_list = {
					name = bride_show_subject_list
					target = root
					days = 10
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			brave = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -0.2
				ai_greed = -0.2
			}
			opinion_modifier = {
				opinion_target = scope:liege
				multiplier = 1
				max = 30
			}
			modifier = {
				is_obedient_to = scope:liege
				scope:liege = {
					government_has_flag = government_is_nomadic
				}
				add = 500
			}
			modifier = { #A scared tributary won't decline
				add = 115
				NOT = { 
					scope:liege = {
						government_has_flag = government_is_nomadic
					}
				}
				trigger_if = {
					limit = {
						highest_held_title_tier > scope:liege.highest_held_title_tier
					}
					has_dread_level_towards = {
						target = scope:liege
						level >= 2
					}
				}
				trigger_else_if = {
					limit = {
						highest_held_title_tier = scope:liege.highest_held_title_tier
					}
					has_dread_level_towards = {
						target = scope:liege
						level >= 1
					}
				}
				trigger_else = {
					always = no
				}
			}

			modifier = {
				has_trait = arrogant
				add = -25
			}
			modifier = {
				has_trait = brave
				add = -25
			}
			modifier = {
				has_trait = disloyal
				add = -15
			}
			modifier = {
				has_trait = loyal
				add = 15
			}
			modifier = {
				has_trait = craven
				add = 25
			}

			modifier = { #Kings are less likely to send their relatives
				highest_held_title_tier >= tier_kingdom
				add = -10
			}
			modifier = {
				hp_accepts_harems = no
				scope:liege = {
					hp_accepts_harems = yes
				}
				add = -25
			}
		}
	}
	#I shall refuse!
	option = {
		name = bride_show.0007.c
		trigger = {
			NOT = {
				is_vassal_of = scope:liege
			}
		}
		if = {
			limit = {
				scope:liege.highest_held_title_tier >= tier_empire
			}
			add_prestige = medium_prestige_gain
		}
		else_if = {
			limit = {
				scope:liege.highest_held_title_tier >= tier_kingdom
			}
			add_prestige = minor_prestige_gain
		}
		else = {
			add_prestige = miniscule_prestige_gain
		}
		scope:liege = {
			hidden_effect = {
				if = {
					limit = {
						is_ai = no
					}
					send_interface_toast = {
						type = event_generic_bad
						title = bride_show.0007.c.t
						right_icon = root
						custom_tooltip = bride_show.0007.c.desc
					}
				}
			}
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -15
			}
		}
		stress_impact = {
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.2
				ai_greed = 0.2
			}
			opinion_modifier = {
				opinion_target = scope:liege
				multiplier = -1
				max = 30
			}
			modifier = {
				NOT = { is_obedient_to = scope:liege }
				scope:liege = {
					government_has_flag = government_is_nomadic
				}
				add = 400
			}
			modifier = { #A scared tributary won't decline
				add = 100
				NOT = { 
					scope:liege = {
						government_has_flag = government_is_nomadic
					}
				}
				has_dread_level_towards = {
					target = scope:liege
					level = 0
				}
			}
			modifier = { #A scared tributary won't decline
				add = 100
				NOT = { 
					scope:liege = {
						government_has_flag = government_is_nomadic
					}
				}
				trigger_if = {
					limit = {
						highest_held_title_tier > scope:liege.highest_held_title_tier
					}
					has_dread_level_towards = {
						target = scope:liege
						level <= 1
					}
				}
				trigger_else_if = {
					limit = {
						highest_held_title_tier = scope:liege.highest_held_title_tier
					}
					has_dread_level_towards = {
						target = scope:liege
						level < 1
					}
				}
				trigger_else = {
					always = no
				}
			}

			modifier = {
				has_trait = arrogant
				add = 25
			}
			modifier = {
				has_trait = brave
				add = 25
			}
			modifier = {
				has_trait = disloyal
				add = 15
			}
			modifier = {
				has_trait = loyal
				add = -15
			}
			modifier = {
				has_trait = craven
				add = -25
			}

			modifier = { #Kings are less likely to send their relatives
				highest_held_title_tier >= tier_kingdom
				add = 15
			}
			modifier = {
				hp_accepts_harems = no
				scope:liege = {
					hp_accepts_harems = yes
				}
				add = 25
			}
		}
	}
}

################
##Notification##
################
bride_show.0008 = {
	type = letter_event
	opening = {
		first_valid = {
			triggered_desc = { #Imperial decree
			    trigger = {
					scope:liege = {
						highest_held_title_tier = tier_empire
					}
				}
				desc = bride_show.imperial.desc
			}
			triggered_desc = { #Royal decree
			    trigger = {
					scope:liege = {
						highest_held_title_tier = tier_kingdom
					}
				}
				desc = bride_show.royal.desc
			}
			triggered_desc = { #Princely decree
			    trigger = {
					scope:liege = {
						any_parent = {
							highest_held_title_tier >= tier_kingdom
						}
					}
				}
				desc = bride_show.princely.desc
			}
			desc = bride_show.noble.desc
		}
	}
	desc = {
		first_valid = {
			triggered_desc = { #Chosen as a spouse
				trigger = {
					scope:candidate_marriage ?= scope:potential_candidate
				}
				desc = bride_show.married.desc
			}
			triggered_desc = { #Chosen as a consort
				trigger = {
					scope:candidate_concubinage ?= scope:potential_candidate
				}
				desc = bride_show.concubine.desc
			}
			triggered_desc = { #Recruited to court
				trigger = {
					scope:candidate_courtier ?= scope:potential_candidate
				}
				desc = bride_show.recruit.desc
			}
			#Fallback
			desc = bride_show.fallback.desc
		}
	}
	sender = scope:liege
	
	immediate = {
		scope:liege = {
			show_as_tooltip = {
				pay_short_term_gold = {
					target = root
					gold = scope:gold_to_pay
				}
			}
			#Prestige
			if = {
				limit = {
					root = {
						any_close_family_member = {
							this = scope:potential_candidate
						}
					}
				}
				if = {
					limit = {
						scope:candidate_marriage ?= scope:potential_candidate
					}
					if = {
						limit = {
							highest_held_title_tier = tier_duchy
						}
						root = {
							add_prestige = miniscule_prestige_value
						}
					}
					else_if = {
						limit = {
							highest_held_title_tier = tier_kingdom
						}
						root = {
							add_prestige = minor_prestige_value
						}
					}
					else_if = {
						limit = {
							highest_held_title_tier >= tier_empire
						}
						root = {
							add_prestige = medium_prestige_value
						}
					}
				}
				else_if = {
					limit = {
						scope:candidate_concubinage ?= scope:potential_candidate
					}
					#Prestige
					if = {
						limit = {
							highest_held_title_tier = tier_kingdom
						}
						root = {
							add_prestige = miniscule_prestige_value
						}
					}
					else_if = {
						limit = {
							highest_held_title_tier >= tier_empire
						}
						root = {
							add_prestige = minor_prestige_value
						}
					}
				}
				else_if  ={
					limit = {
						scope:candidate_courtier ?= scope:potential_candidate
					}
					root = {
						add_prestige = miniscule_prestige_value
					}
				}
			}
		}
		gain_influence_harem_politics_effect = {
			RECIPIENT = root
			CHARACTER = scope:liege
			TARGET = scope:potential_candidate
		}
	}

	option = {
		name = bride_show.0007.a
		ai_chance = {
			base = 1
		}
	}
}

bride_show.1000 = { 
	type = character_event
	title = bride_show.1000.t
	desc = bride_show.1000.desc
	theme = realm
	
	left_portrait = { 	
		character = root
		animation = personality_greedy
	}
	right_portrait = {
		character = scope:tributary_scope
		animation = disapproval
	}
	
	trigger = {
		any_in_list = {
			list = bride_show_preliminary_list
			harem_politics_is_valid_bride_show_subject_trigger = {
				OVERLORD = scope:liege
			}
			NOT = {
				is_vassal_of = scope:liege
			}
			count >= 1
		}
	}
	immediate = {
		ordered_in_list = {
			list = bride_show_preliminary_list
			limit = {
				NOT = {
					is_vassal_of = scope:liege
				}
			}
			order_by = {
				value = primary_title.tier
				add = dominance_value
			}
			save_scope_as = tributary_scope
		}
	}

	#Invite tributaries' courtiers
	option = {
		name = bride_show.1000.a
		custom_tooltip = bride_show_tributary_invite_effect_tooltip
		custom_tooltip = bride_show_tributary_opinion_effect_tooltip
		add_prestige = minor_prestige_loss
		set_local_variable = {
			name = bride_show_tributary_participation
			value = yes
		}
		stress_impact = {
			craven = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = 1
			}
			modifier = { #Stress
				has_trait = craven
				add = -25
			}
			modifier = {
				has_trait = shy
				add = -25
			}


			modifier = {
				trigger_if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					any_in_list = {
						list = bride_show_preliminary_list
						count = 4
					}
				}
				trigger_else = {
					any_in_list = {
						list = bride_show_preliminary_list
						count = 3
					}
				}
				add = 20
			}

			modifier = {
				any_tributary = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					count >= 2
				}
				add = 10
			}
			modifier = {
				any_tributary = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					count >= 3
				}
				add = 10
			}
			modifier = {
				prestige <= minor_prestige_value
				add = -50
			}
		}
	}

	#Do not invite them
	option = {
		name = bride_show.1000.c

		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = -1
			}
			modifier = {
				has_trait = greedy
				add = -25
			}

			modifier = {
				prestige <= minor_prestige_value
				add = 100
			}
		}
	}

	after = {
		trigger_event = {
			id = bride_show.0001
			days = { 10 14 }
		}
		clear_saved_scope = tributary_scope
		every_in_list = {
			list = bride_show_preliminary_list
			remove_from_list = bride_show_preliminary_list
		}
	}
}

##Managing the eligible subjects##
bride_show.1001 = { 
	hidden = yes
	immediate = {
		if = {
			limit = {
				any_in_list = {
					list = bride_show_preliminary_list
					count >= 1
				}
			}
			every_in_list = {
				list = bride_show_preliminary_list
				remove_from_list = bride_show_preliminary_list
			}
		}
		if = {
			limit = {
				any_vassal = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					any_courtier = {
						bride_show_viable_candidate_trigger = {
							OVERLORD = scope:liege
						} 
					}
					count >= 1
				}
			}
			every_vassal = {
				limit = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					any_courtier = {
						bride_show_viable_candidate_trigger = {
							OVERLORD = scope:liege
						} 
					}
				}
				trigger_event = bride_show.0007
			}
		}
		if = {
			limit = {
				any_tributary = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					any_courtier = {
						bride_show_viable_candidate_trigger = {
							OVERLORD = scope:liege
						} 
					}
					count >= 1
				}
				exists = local_var:bride_show_tributary_participation
			}
			every_tributary = {
				limit = {
					harem_politics_is_valid_bride_show_subject_trigger = {
						OVERLORD = scope:liege
					}
					any_courtier = {
						bride_show_viable_candidate_trigger = {
							OVERLORD = scope:liege
						} 
					}
				}
				trigger_event = bride_show.0007
			}
		}
		trigger_event = {
			id = bride_show.0004
			days = 1
		}
	}
}

bride_show.1002 = {
	hidden = yes
	trigger = {
		any_in_list = {
			list = elegible_candidates_list
			is_courtier_of = root
			count >= 1
		}
	}
	immediate = {
		save_scope_as = subject
		if = {
			limit = {
				any_in_list = {
					list = elegible_candidates_list
					is_courtier_of = root
					count > 1
				}
			}
			set_variable = {
				name = num_courtiers_summoned
				value = -1
			}
			every_in_list = {
				list = elegible_candidates_list
				limit = {
					is_courtier_of = root
				}
				root = {
					change_variable = {
						name = num_courtiers_summoned
						add = 1
					}
				}
				add_to_list = summoned_courtiers_list
			}
			ordered_in_list = {
				list = summoned_courtiers_list

				order_by = {
					value = bride_show_candidate_weights_for_root_value
				}
				if = {
					limit = {
						NOT = {
							exists = scope:drafted_candidate
						}
					}
					save_scope_as = drafted_candidate
				}
				remove_from_list = summoned_courtiers_list
			}
		}
		else = {
			random_in_list = {
				list = elegible_candidates_list
				limit = {
					is_courtier_of = root
				}
				save_scope_as = drafted_candidate
			}
		}

		send_interface_toast = {
			type = event_generic_neutral
			title = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:liege = {
								is_female = yes
							}
						}
						desc = bride_show.0005_f.t
					}
					desc = bride_show.0005_m.t
				}
			}
			right_icon = scope:liege
			left_icon = scope:drafted_candidate
			if = {
				limit = {
					NOT = {
						has_variable = num_courtiers_summoned
					}
				}
				custom_tooltip = bride_show_1_courtiers_desc
			}
			else = {
				custom_tooltip = bride_show_more_courtiers_desc
				remove_variable = num_courtiers_summoned
			}
		}
	}
}

##Recruit Jarya##
bride_show.2000 = {
	hidden = yes
	trigger = {
		is_landed = yes
		hp_accepts_concubinage = yes
		religion = religion:islam_religion
		highest_held_title_tier >= tier_duchy
		trigger_if = {
			limit = {
				has_variable = jarya_recruited
			}
			var:jarya_recruited < 4
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:liege }
			}
			save_scope_as = liege
		}
		if = {
			limit = {
				NOT = { exists = scope:harem_liege }
			}
			save_scope_as = harem_liege
		}
		if = {
			limit = {
				any_in_list = {
					list = pool_candidates
					NOT = { is_courtier_of = scope:liege }
					recruit_concubines_viable_candidate_trigger = {
						OVERLORD = scope:liege
					}
					count = 0
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:concubine_location }
				}
				hp_select_concubine_location_effect = yes
			}
			calyver_create_candidate_effect = yes
		}
		if = {
			limit = {
				any_in_list = {
					list = pool_candidates
					NOT = { is_courtier_of = scope:liege }
					recruit_concubines_viable_candidate_trigger = {
						OVERLORD = scope:liege
					}
					count = 1
				}
			}
			random_in_list = {
				list = pool_candidates
				limit = {
					NOT = { is_courtier_of = scope:liege }
					recruit_concubines_viable_candidate_trigger = {
						OVERLORD = scope:liege
					}
				}
				save_scope_as = jarya
			}
		}
		else = {
			random_in_list = {
				list = pool_candidates
				limit = {
					NOT = { is_courtier_of = scope:liege }
					recruit_concubines_viable_candidate_trigger = {
						OVERLORD = scope:liege
					}
				}
				weight = {
					base = 50
					modifier = {
						exists = court_owner
						add = -25
					}
					modifier = { # More likely to be captured near bodies of water
						location ?= {
							OR = {
								is_sea_province = yes
								is_riverside_province = yes
								county ?= {
									OR = {
										is_coastal_county = yes
										is_riverside_county = yes
									}
								}
							}
						}
						add = 30
					}
					modifier = { # Christians were especially captured
						religion = religion:christianity_religion
						add = 30
					}
					modifier = {
						location ?= {
							geographical_region = world_europe
						}
						add = 20
					}
					modifier = {
						location ?= {
							geographical_region = world_europe_south
						}
						add = 20
					}
					modifier = {
						location ?= {
							geographical_region = world_europe_west_iberia
						}
						add = 20
					}
					modifier = {
						is_lowborn = no
						add = -10
					}
					# Virginity was prized
					modifier = {
						is_virgin_trigger = yes
						add = 25
					}
					# Skills
					modifier = {
						OR = {
							stewardship >= 9
							diplomacy >= 9
							learning >= 9
						}
						add = 10
					}
					modifier = {
						OR = {
							stewardship >= 13
							diplomacy >= 13
							learning >= 13
						}
						add = 15
					}
					modifier = {
						OR = {
							stewardship >= 17
							diplomacy >= 17
							learning >= 17
						}
						add = 20
					}
					modifier = {
						AND = {
							stewardship >= 13
							diplomacy >= 13
							learning >= 13
						}
						add = 25
					}
					# Good genetics
					modifier = { #Trait considerations
						num_of_good_genetic_traits >= 1
						add = 15
					}
					modifier = {
						num_of_good_genetic_traits >= 2
						add = 20
					}
					# No bad genetic traits
					modifier = {
						num_of_bad_genetic_traits > 0
						add = -25
					}
					# Docile captives would be easier to send
					modifier = {
						has_trait = temperate
						add = 10
					}
					modifier = {
						has_trait = craven
						add = 10
					}
					modifier = {
						has_trait = content
						add = 10
					}
					modifier = {
						has_trait = humble
						add = 10
					}
					modifier = {
						has_trait = lustful
						add = 10
					}
					modifier = {
						has_trait = chaste
						add = -10
					}
					modifier = {
						has_trait = zealous
						add = -20
					}
					# Intellect
					modifier = {
						has_trait = intellect_good_1
						add = 5
					}
					modifier = {
						has_trait = intellect_good_2
						add = 10
					}
					modifier = {
						has_trait = intellect_good_3
						add = 15
					}
					modifier = {
						has_trait = strong
						add = 5
					}
					# Poets
					modifier = {
						has_trait = poet
						add = 5
					}
					modifier = {
						has_trait = poet
						scope:liege = { highest_held_title_tier >= tier_kingdom }
						add = 10
					}
					# Skills
					modifier = { #Diplomacy
						add = {
							value = diplomacy
							divide = 2
						}
					}
					modifier = { #Learning
						add = {
							value = learning
							divide = 2
						}
					}
					modifier = { #Intrigue
						add = {
							value = intrigue
							divide = 2
						}
					}
					# Health
					modifier = {
						is_healthy = yes
						add = 20
					}
					modifier = {
						OR = {
							has_character_modifier = malnourished_modifier
							current_weight < -50
							has_character_modifier = obese_modifier
							current_weight > 50
							has_trait = beauty_bad
						}
						add = -20
					}		
				}
				save_scope_as = jarya
			}
		}
		if = {
			limit = {	
				scope:jarya.court_owner ?= {
					NOR = {
						this = scope:liege
						is_close_family_of = scope:jarya
					}
					is_ai = no
				}
			}
			scope:jarya.court_owner = {
				send_interface_toast = {
					type = event_generic_bad
					title = bride_show.2000.t.court_owner
					right_icon = scope:liege
					left_icon = scope:jarya
					custom_tooltip = bride_show.2000.desc.court_owner
				}
			}
		}
		send_interface_toast = {
			type = event_generic_neutral
			title = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:jarya = { is_female = yes }
						}
						desc = bride_show.2000.t_f
					}
					desc = bride_show.2000.t_m
				}
			}
			right_icon = scope:jarya
			scope:liege = {
				add_courtier = scope:jarya
			}
			scope:jarya = {
				add_opinion = {
					target = scope:liege
					modifier = upset_opinion
					opinion = -10
				}
				stress_impact = {
					base = minor_stress_impact_gain
				}
				#In case they received a marriage proposal already
				# add_character_flag = {
				# 	flag = has_been_offered_as_concubine
				# 	days = 1
				# }
				add_character_flag = {
					flag = recently_abducted_concubine
					years = 2
				}
				remove_from_list = pool_candidates
				add_character_flag = {
					flag = blocked_from_leaving
					years = 5
				}
				hidden_effect = {
					return_to_court = yes
					# Chance of conversion to liege's faith
					if = {
						limit = {
							NOR = {
								has_trait = zealous 
								faith = scope:liege.faith
							}
						}
						random = {
							chance = 50
							# Based on current faith
							modifier = {
								faith = {
									faith_hostility_level = {
										target = scope:liege.faith
										value = faith_fully_accepted_level
									}
								}
								add = 30
							}
							modifier = {
								faith = {
									faith_hostility_level = {
										target = scope:liege.faith
										value >= faith_astray_level
									}
								}
								add = -15
							}
							modifier = {
								faith = {
									faith_hostility_level = {
										target = scope:liege.faith
										value >= faith_hostile_level
									}
								}
								add = -15
							}
							modifier = {
								faith = {
									faith_hostility_level = {
										target = scope:liege.faith
										value >= faith_evil_level
									}
								}
								add = -15
							}
							modifier = {
								hp_accepts_harems = yes
								add = 10
							}
							# Based on traits
							modifier = {
								has_trait = cynical
								add = 20
							}
							modifier = {
								has_trait = ambitious
								add = 20
							}
							modifier = {
								has_trait = greedy
								add = 20
							}
							modifier = {
								has_trait = arrogant
								add = 20
							}
							modifier = {
								has_trait = craven
								add = 20
							}
							# Younger characters are more likely to change faiths
							modifier = {
								age < 20
								add = 15
							}
							# Kings and Emperors are more likely to force their servants to convert
							modifier = {
								scope:liege.highest_held_title_tier >= tier_kingdom
								add = 15
							}
							# Zealous rulers are more likely to recruit converted concubines
							modifier = {
								scope:liege = { has_trait = zealous }
								add = 15
							}
							# Cynical rulers don't care much about concubines' faith
							modifier = {
								scope:liege = { has_trait = cynical }
								add = -15
							}
							if = {
								limit = {
									NOT = {
										has_character_flag = abducted_non_believer
									}
								}
								add_character_flag = {
									flag = abducted_non_believer
									years = 5
								}
							}
							set_character_faith = scope:liege.faith
						}
					}
					if = {
						limit = {
							exists = betrothed
							#A check to make sure you haven't somehow gotten betrothed to them during the consideration time
							NOT = { betrothed = scope:actor }
						}
						betrothed = { trigger_event = marriage_interaction.0041 }
						break_betrothal = betrothed
					}
					if = {
						limit = {
							any_close_family_member = {
								NOT = { this = scope:liege }
								count >= 1
							}
						}
						every_close_family_member = {
							limit = {
								NOT = { this = scope:liege }
							}
							add_opinion = {
								target = scope:liege
								modifier = abducted_close_family_crime
							}
							if = {
								limit = {
									is_ai = no
								}
								send_interface_toast = {
									type = event_generic_bad
									title = bride_show.2000.t.close_family
									right_icon = scope:liege
									left_icon = scope:jarya
									custom_tooltip = bride_show.2000.desc.court_owner
								}
							}
						}
					}
					# They should be lowborn
					if = {
						limit = {
							house ?= {
								any_house_member = {
									count = 1
								}
							}
						}
						set_to_lowborn = yes
					}
				}
				# remove_character_flag = has_been_offered_as_concubine
			}
		}
		if = {
			limit = {
				NOT = {
					has_variable = jarya_recruited
				}
			}
			set_variable = {
				name = jarya_recruited
				value = 1
				months = 6
			}
			if = {
				limit = {
					highest_held_title_tier = tier_duchy
				}
				random = {
					chance = 50
					modifier = {
						has_trait = lustful
						add = 10
					}
					trigger_event = {
						id = bride_show.2000
						days = { 7 10 }
					}
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier > tier_duchy
				}
				trigger_event = {
					id = bride_show.2000
					days = { 7 10 }
				}
			}
		}
		else = {
			change_variable = {
				name = jarya_recruited
				add = 1
			}
			# Should we repeat the event?
			# For dukes, the maximum is 3
			if = {
				limit = {
					highest_held_title_tier = tier_duchy
				}
				if = {
					limit = {
						var:jarya_recruited < 3
					}
					random = {
						chance = 25
						modifier = {
							has_trait = lustful
							add = 10
						}
						trigger_event = {
							id = bride_show.2000
							days = { 7 10 }
						}
					}
				}
				else = {
					remove_variable = jarya_recruited
				}
			}
			# For kings+, the maximum is 4
			if = {
				limit = {
					highest_held_title_tier > tier_duchy
				}
				if = {
					limit = {
						var:jarya_recruited < 3
					}
					random = {
						chance = 50
						modifier = {
							has_trait = lustful
							add = 10
						}
						trigger_event = {
							id = bride_show.2000
							days = { 7 10 }
						}
					}
				}
				else_if = {
					limit = {
						var:jarya_recruited = 3
					}
					random = {
						chance = 25
						modifier = {
							has_trait = lustful
							add = 10
						}
						modifier = {
							highest_held_title_tier > tier_kingdom
							add = 10
						}
						trigger_event = {
							id = bride_show.2000
							days = { 7 10 }
						}
					}
				}
				else_if = {
					limit = {
						var:jarya_recruited > 3	
					}
					remove_variable = jarya_recruited
				}
			}
		}
		# The AI is a bit slow and will sometimes convert them to Islam before taking them as concubines
		if = {
			limit = {
				is_ai = yes
				is_character_interaction_valid = {
					recipient = scope:jarya
					interaction = ai_make_concubine_interaction
				}
			}
			random = {
				chance = 10
				modifier = {
					number_of_concubines < number_of_desired_concubines
					add = 60
				}
				modifier = {
					scope:jarya = {
						num_of_good_genetic_traits > 0
					}
					add = 25
				}
				modifier = {
					scope:jarya = {
						num_of_bad_genetic_traits > 0
					}
					add = -50
				}
				modifier = {
					scope:jarya = {
						can_have_children_with = { CHARACTER = scope:liege } # Only if you can have kids since this is about fertility and genetic traits
						fertility > 0.2
					}
					add = 10
				}
				modifier = {
					is_attracted_to_gender_of = scope:jarya
					add = 10
				}
				modifier = {
					NOT = { is_attracted_to_gender_of = scope:jarya }
					add = -25
				}
				modifier = {
					OR = { 
						has_relation_lover = scope:jarya
						has_relation_friend = scope:jarya
						has_relation_soulmate = scope:jarya
						has_relation_best_friend = scope:jarya
					}
					add = 60
				}
				run_interaction = {
					interaction = ai_make_concubine_interaction
					actor = scope:liege
					recipient = scope:jarya
					execute_threshold = accept
				}
			}
		}
	}
}
